package com.dianping.cat.consumer.heartbeat.model.transform;

import com.dianping.cat.consumer.heartbeat.model.entity.Detail;
import com.dianping.cat.consumer.heartbeat.model.entity.Disk;
import com.dianping.cat.consumer.heartbeat.model.entity.Extension;
import com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport;
import com.dianping.cat.consumer.heartbeat.model.entity.Machine;
import com.dianping.cat.consumer.heartbeat.model.entity.Period;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import org.xml.sax.Attributes;

























public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Detail buildDetail(Attributes attributes) {
/*  45 */     String id = attributes.getValue("id");
/*  46 */     String value = attributes.getValue("value");
/*  47 */     Detail detail = new Detail(id);

/*  49 */     if (value != null) {
/*  50 */       detail.setValue(((Double)convert(Double.class, value, Double.valueOf(0.0D))).doubleValue());
    }

/*  53 */     return detail;
  }


  public Disk buildDisk(Attributes attributes) {
/*  58 */     String path = attributes.getValue("path");
/*  59 */     String total = attributes.getValue("total");
/*  60 */     String free = attributes.getValue("free");
/*  61 */     String usable = attributes.getValue("usable");
/*  62 */     Disk disk = new Disk(path);

/*  64 */     if (total != null) {
/*  65 */       disk.setTotal(((Long)convert(Long.class, total, Long.valueOf(0L))).longValue());
    }

/*  68 */     if (free != null) {
/*  69 */       disk.setFree(((Long)convert(Long.class, free, Long.valueOf(0L))).longValue());
    }

/*  72 */     if (usable != null) {
/*  73 */       disk.setUsable(((Long)convert(Long.class, usable, Long.valueOf(0L))).longValue());
    }

/*  76 */     return disk;
  }



/*  81 */   public String buildDomain(Attributes attributes) { throw new UnsupportedOperationException(); }



  public Extension buildExtension(Attributes attributes) {
/*  86 */     String id = attributes.getValue("id");
/*  87 */     return new Extension(id);
  }




  public HeartbeatReport buildHeartbeatReport(Attributes attributes) {
/*  94 */     String domain = attributes.getValue("domain");
/*  95 */     String startTime = attributes.getValue("startTime");
/*  96 */     String endTime = attributes.getValue("endTime");
/*  97 */     HeartbeatReport heartbeatReport = new HeartbeatReport(domain);

/*  99 */     if (startTime != null) {
/* 100 */       heartbeatReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 103 */     if (endTime != null) {
/* 104 */       heartbeatReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 107 */     return heartbeatReport;
  }



/* 112 */   public String buildIp(Attributes attributes) { throw new UnsupportedOperationException(); }



  public Machine buildMachine(Attributes attributes) {
/* 117 */     String ip = attributes.getValue("ip");
/* 118 */     String classpath = attributes.getValue("classpath");
/* 119 */     Machine machine = new Machine(ip);

/* 121 */     if (classpath != null) {
/* 122 */       machine.setClasspath(classpath);
    }

/* 125 */     return machine;
  }


  public Period buildPeriod(Attributes attributes) {
/* 130 */     String minute = attributes.getValue("minute");
/* 131 */     String threadCount = attributes.getValue("thread-count");
/* 132 */     String daemonCount = attributes.getValue("daemon-count");
/* 133 */     String totalStartedCount = attributes.getValue("total-started-count");
/* 134 */     String catThreadCount = attributes.getValue("cat-thread-count");
/* 135 */     String pigeonThreadCount = attributes.getValue("pigeon-thread-count");
/* 136 */     String httpThreadCount = attributes.getValue("http-thread-count");
/* 137 */     String newGcCount = attributes.getValue("new-gc-count");
/* 138 */     String oldGcCount = attributes.getValue("old-gc-count");
/* 139 */     String memoryFree = attributes.getValue("memory-free");
/* 140 */     String heapUsage = attributes.getValue("heap-usage");
/* 141 */     String noneHeapUsage = attributes.getValue("none-heap-usage");
/* 142 */     String systemLoadAverage = attributes.getValue("system-load-average");
/* 143 */     String catMessageProduced = attributes.getValue("cat-message-produced");
/* 144 */     String catMessageOverflow = attributes.getValue("cat-message-overflow");
/* 145 */     String catMessageSize = attributes.getValue("cat-message-size");
/* 146 */     Period period = new Period((minute == null) ? 0 : ((Integer)convert(Integer.class, minute, Integer.valueOf(0))).intValue());

/* 148 */     if (threadCount != null) {
/* 149 */       period.setThreadCount(((Integer)convert(Integer.class, threadCount, Integer.valueOf(0))).intValue());
    }

/* 152 */     if (daemonCount != null) {
/* 153 */       period.setDaemonCount(((Integer)convert(Integer.class, daemonCount, Integer.valueOf(0))).intValue());
    }

/* 156 */     if (totalStartedCount != null) {
/* 157 */       period.setTotalStartedCount(((Integer)convert(Integer.class, totalStartedCount, Integer.valueOf(0))).intValue());
    }

/* 160 */     if (catThreadCount != null) {
/* 161 */       period.setCatThreadCount(((Integer)convert(Integer.class, catThreadCount, Integer.valueOf(0))).intValue());
    }

/* 164 */     if (pigeonThreadCount != null) {
/* 165 */       period.setPigeonThreadCount(((Integer)convert(Integer.class, pigeonThreadCount, Integer.valueOf(0))).intValue());
    }

/* 168 */     if (httpThreadCount != null) {
/* 169 */       period.setHttpThreadCount(((Integer)convert(Integer.class, httpThreadCount, Integer.valueOf(0))).intValue());
    }

/* 172 */     if (newGcCount != null) {
/* 173 */       period.setNewGcCount(((Long)convert(Long.class, newGcCount, Long.valueOf(0L))).longValue());
    }

/* 176 */     if (oldGcCount != null) {
/* 177 */       period.setOldGcCount(((Long)convert(Long.class, oldGcCount, Long.valueOf(0L))).longValue());
    }

/* 180 */     if (memoryFree != null) {
/* 181 */       period.setMemoryFree(((Long)convert(Long.class, memoryFree, Long.valueOf(0L))).longValue());
    }

/* 184 */     if (heapUsage != null) {
/* 185 */       period.setHeapUsage(((Long)convert(Long.class, heapUsage, Long.valueOf(0L))).longValue());
    }

/* 188 */     if (noneHeapUsage != null) {
/* 189 */       period.setNoneHeapUsage(((Long)convert(Long.class, noneHeapUsage, Long.valueOf(0L))).longValue());
    }

/* 192 */     if (systemLoadAverage != null) {
/* 193 */       period.setSystemLoadAverage(toNumber(systemLoadAverage, "0.00", Integer.valueOf(0)).doubleValue());
    }

/* 196 */     if (catMessageProduced != null) {
/* 197 */       period.setCatMessageProduced(((Long)convert(Long.class, catMessageProduced, Long.valueOf(0L))).longValue());
    }

/* 200 */     if (catMessageOverflow != null) {
/* 201 */       period.setCatMessageOverflow(((Long)convert(Long.class, catMessageOverflow, Long.valueOf(0L))).longValue());
    }

/* 204 */     if (catMessageSize != null) {
/* 205 */       period.setCatMessageSize(toNumber(catMessageSize, "0.00", Integer.valueOf(0)).doubleValue());
    }

/* 208 */     Map<String, String> dynamicAttributes = period.getDynamicAttributes();
/* 209 */     int _length = (attributes == null) ? 0 : attributes.getLength();

/* 211 */     for (int i = 0; i < _length; i++) {
/* 212 */       String _name = attributes.getQName(i);
/* 213 */       String _value = attributes.getValue(i);

/* 215 */       dynamicAttributes.put(_name, _value);
    }

/* 218 */     dynamicAttributes.remove("minute");
/* 219 */     dynamicAttributes.remove("thread-count");
/* 220 */     dynamicAttributes.remove("daemon-count");
/* 221 */     dynamicAttributes.remove("total-started-count");
/* 222 */     dynamicAttributes.remove("cat-thread-count");
/* 223 */     dynamicAttributes.remove("pigeon-thread-count");
/* 224 */     dynamicAttributes.remove("http-thread-count");
/* 225 */     dynamicAttributes.remove("new-gc-count");
/* 226 */     dynamicAttributes.remove("old-gc-count");
/* 227 */     dynamicAttributes.remove("memory-free");
/* 228 */     dynamicAttributes.remove("heap-usage");
/* 229 */     dynamicAttributes.remove("none-heap-usage");
/* 230 */     dynamicAttributes.remove("system-load-average");
/* 231 */     dynamicAttributes.remove("cat-message-produced");
/* 232 */     dynamicAttributes.remove("cat-message-overflow");
/* 233 */     dynamicAttributes.remove("cat-message-size");

/* 235 */     return period;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 240 */     if (value == null || value.length() == 0) {
/* 241 */       return defaultValue;
    }

/* 244 */     if (type == Boolean.class || type == boolean.class)
/* 245 */       return (T)Boolean.valueOf(value); 
/* 246 */     if (type == Integer.class || type == int.class)
/* 247 */       return (T)Integer.valueOf(value); 
/* 248 */     if (type == Long.class || type == long.class)
/* 249 */       return (T)Long.valueOf(value); 
/* 250 */     if (type == Short.class || type == short.class)
/* 251 */       return (T)Short.valueOf(value); 
/* 252 */     if (type == Float.class || type == float.class)
/* 253 */       return (T)Float.valueOf(value); 
/* 254 */     if (type == Double.class || type == double.class)
/* 255 */       return (T)Double.valueOf(value); 
/* 256 */     if (type == Byte.class || type == byte.class)
/* 257 */       return (T)Byte.valueOf(value); 
/* 258 */     if (type == Character.class || type == char.class) {
/* 259 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 261 */     return (T)value;
  }


  protected Date toDate(String str, String format, Date defaultValue) {
/* 266 */     if (str == null || str.length() == 0) {
/* 267 */       return defaultValue;
    }

    try {
/* 271 */       return (new SimpleDateFormat(format)).parse(str);
/* 272 */     } catch (ParseException e) {
/* 273 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }

  protected Number toNumber(String str, String format, Number defaultValue) {
/* 278 */     if (str == null || str.length() == 0) {
/* 279 */       return defaultValue;
    }

    try {
/* 283 */       return (new DecimalFormat(format)).parse(str);
/* 284 */     } catch (ParseException e) {
/* 285 */       throw new RuntimeException(String.format("Unable to parse number(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/heartbeat/model/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */